<template>
	<view class="container">
		<view class="header">
			<view class="step active">
				<view class="step-num">
					1
				</view>
				<view class="step-text">
					填写任务需求
				</view>
			</view>
			<view class="step-arrow">
				<view class="icon-arrow">
					<image src="../../../static/images/arrow-half.png" mode=""></image>
				</view>
			</view>
			<view class="step">
				<view class="step-num">
					2
				</view>
				<view class="step-text">
					设置任务详情
				</view>
			</view>
		</view>
		<view class="main">
			<view class="card">
				<view class="taskType">
					<view class="task-dot"></view>
					<text>任务类型：拼多多</text>
				</view>
				<view class="task-line">
					<view class="task-down">
						<image src="../../../static/images/arrow-down.png" mode=""></image>
					</view>
					<view class="taskline"></view>
				</view>
				<view class="taskClass">
					<radio-group class="radio-group" @change="classChange">
						<label class="tui-radio" >
							<radio value="1" color="#e03e2f" style="transform: scale(.8);"  :checked="classType === 1" /><text>拼多多砍价任务</text> 
						</label>
						<label class="tui-radio">
							<radio value="2" color="#e03e2f" style="transform: scale(.8);"  :checked="classType === 2"  /><text>拼多多领现金任务</text>
						</label>
					</radio-group>
				</view>
			</view>
			<view class="card">
				<view class="cardItem">
					<view class="cardItem-left">
						<text class="iconfont iconicon-test"></text><text class="title">任务单数</text> 
					</view>
					<view class="cardItem-right">
						<input type="number" value="" v-model="formData.item_quantity" maxlength="4" placeholder="需要多少人帮你完成" />
					</view>
				</view>
				<view class="task-line task-line2">
					<view class="task-down">
					</view>
					<view class="taskline"></view>
				</view>
				<view class="cardItem">
					<view class="cardItem-left">
						<text class="iconfont iconicon-test"></text><text class="title">任务价格</text> 
					</view>
					<view class="cardItem-right">
						<view class="selectResult">
							<picker @change="handleMoney" :value="moneyIndex" :range="moneyArray">
									<view class="uni-input">{{moneyValue}}</view>
							</picker>
						</view>
						<text class="iconfont iconicon-"></text>
					</view>
				</view>
			</view>
			<view class="card">
				<view class="cardItem">
					<view class="cardItem-left">
						<text class="iconfont iconshijian"></text><text class="title">有效时间</text> 
					</view>
					<view class="cardItem-right">
						<view class="selectResult">
							<picker @change="handleTime" :value="timeIndex" :range="timeArray">
									<view class="uni-input">{{timeValue}}</view>
							</picker>
						</view>
						<text class="iconfont iconicon-"></text>
					</view>
				</view>
			</view>
		</view>
		<view class="tips">
			平台不支持设置砍价金额和其他要求，接单者帮你砍价大于0元都属于按照要求完成任务
		</view>
		<view class="stepBtn" @click="handleStep">
			下一步
		</view>
	</view>
</template>

<script>
const form = require("@/components/common/tui-validation/tui-validation.js")
	export default {
		components: {
	
		},
		data() {
			return {
				timeIndex: 0,
				timeValue: '选择任务有效时间',
				moneyValue: '为每人支付支付多少金币',
				moneyIndex: 0,
				classType: 1,
				moneyArray: ['500金币/单','600金币/单','700金币/单','800金币/单','900金币/单','1000金币/单','1200金币/单','1500金币/单','1800金币/单','2000金币/单','2500金币/单','3000金币/单','3500金币/单','4000金币/单',],
				timeArray: ['30分钟','1小时', '6小时', '1天', '2天', '3天'],
				timeSecond:[30,60,360,1440,2880,4320],
				moneyInit: [500, 600, 700, 800, 900, 1000, 1200, 1500, 1800, 2000, 2500, 3000, 3500, 4000],
				formData: {
					sub_type: 'pdd-kj',
					name: '拼多多砍价任务'
				}
			}
		},
		onReady() {
		},
		onLoad(e) {
			console.log(e)
			this.$set(this.formData, 'type', e.type)
		},
		methods: {
			handleMoney (e) {
				let index = e.target.value
				this.moneyValue = this.moneyArray[index]
				this.$set(this.formData, 'item_price', this.moneyInit[index])
			},
			handleTime (e) {
				let index = e.target.value
				this.timeValue = this.timeArray[index]
				this.$set(this.formData, 'limit_time', this.timeSecond[index])
			},
			handleStep () {
				let rules = [{
					name: "sub_type",
					rule: ["required"], //可使用区间，此处主要测试功能
					msg: ["请选择任务类型"]
				}, {
					name: "item_quantity",
					rule: ["required", "isNum", "range:[10,1000]"],
					msg: ["请输入任务单数", "请输入数字", "任务单数必须大于或等于10"]
				}, {
					name: "item_price",
					rule: ["required"],
					msg: ["请选择任务价格"]
				}, {
					name: "limit_time",
					rule: ["required"],
					msg: ["请选择有效时间"]
				}];
				let checkRes = form.validation(this.formData, rules);
				if (!checkRes) {
					let jsonString = JSON.stringify(this.formData)
					uni.navigateTo({
						url:"/pages/task/pdd/step2?formData=" + jsonString
					})
				} else {
					uni.showToast({
						title: checkRes,
						icon: "none"
					});
				}
			},
			classChange (e) {
				let value = e.target.value
				this.classType = parseInt(value)
				if(this.classType === 1) {
					this.$set(this.formData, 'sub_type', 'pdd-kj')
					this.$set(this.formData, 'name', '拼多多砍价任务')
				} else {
					this.$set(this.formData, 'sub_type', 'pdd-lxj')
					this.$set(this.formData, 'name', '拼多多领现金任务')
				}
				console.log(this.formData)
			}
		}
	}
</script>
<style>
	page {
		background: #F8F8F8;
	}
</style>
<style scoped lang="scss">
	.container {
		.header {
			height: 90rpx;
			padding: 0 110rpx;
			line-height: 90rpx;
			background: linear-gradient(#fc4250, #fe744b);
			display: flex;
			.step {
				display: flex;
				align-items: center;
				opacity: 0.5;
				flex: 1;
				justify-content: center;
				&.active {
					opacity: 1;
				}
				.step-num {
					flex: 0 0 32rpx;
					width: 32rpx;
					height: 32rpx;
					margin-right: 15rpx;
					line-height: 32rpx;
					border-radius: 50%;
					background: #fff;
					font-size: 16rpx;
					color: #e05f59;
					text-align: center;
				}
				.step-text {
					font-size: 22rpx;
					color: #fff;
				}
			}
			.step-arrow {
				display: flex;
				height: 100%;
				align-items: center;
				opacity: 0.5;
				flex:0 0 98rpx;
				text-align: center;
				&.active {
					opacity: 1;
				}
				.icon-arrow {
					width: 48rpx;
					height: 18rpx;
					margin: 0 auto;
					image {
						display: block;
						width: 100%;
						height: 18rpx;
					}
				}
			}
		}

		.main {
			padding: 0 20rpx;
			box-sizing: border-box;
			.card {
				width: 100%;
				padding: 40rpx 28rpx;
				margin-bottom: 22rpx;
				box-sizing: border-box;
				border-radius: 10rpx;
				background: #fff;
				box-shadow: 0 0 10rpx #eee;
				.taskType {
					display: flex;
					align-items: center;
					margin-bottom: 32rpx;
					.task-dot {
						flex:0 0 15rpx;
						width: 15rpx;
						height: 15rpx;
						margin-right: 40rpx;
						background: #ff3957;
						border-radius: 50%;
					}
						text {
							flex: 1;
							font-size: 26rpx;
							color: 000;
							font-weight: bold;
						}
				}
				.task-line {
					display: flex;
					align-items: center;
					margin-bottom: 42rpx;
					.task-down {
						flex:0 0 20rpx;
						width: 20rpx;
						height: 20rpx;
						margin-right: 40rpx;
						image {
							display: block;
							width: 100%;
							height: 100%;
						}
					}
					.taskline {
						flex: 1;
						border-bottom: 1px solid #ededed;
					}
				}
				.taskClass {
					.tui-radio {
						margin-right: 64rpx;
						font-size: 24rpx;
						color: #000;
						radio {
							vertical-align: middle;
						}
						text {
							vertical-align: middle;
						}
					}
				}
				.cardItem {
					display: flex;
					-webkit-box-pack: justify;
					-webkit-justify-content: space-between;
					-ms-flex-pack:justify ;
					justify-content: space-between;
					&:nth-child(1) {
						margin-bottom: 28rpx;
					}
					&:last-child {
						margin-bottom: 0;
					}
					.cardItem-left {
						font-size: 26rpx;
						line-height: 1.4rem;
						text.iconfont {
							font-weight: bold;
							font-size: 32rpx;
							color: #e42a33;
						}
						.title {
							padding-left: 30rpx;
							color: #747474;
						}
					}
					.cardItem-right {
						position: relative;
						padding-right: 28rpx;
						input {
							color: #000;
							font-size: 26rpx;
							text-align: right;
						}
						.selectResult {
							line-height: 1.4rem;
							font-size: 26rpx;
							color: #747474;
						}
						.iconfont {
							position: absolute;
							right: 0;
							top: 50%;
							transform: translateY(-50%) rotate(180deg);
							font-size: 32rpx;
							color: #747474;
						}
					}
				}
				.task-line2 {
					height: 1px;
					margin-bottom: 30rpx;
				}
			}
			
		}
		.tips {
			padding: 28rpx 24rpx 0;
			font-size: 24rpx;
			color: #6c6c6c;
		}
		.stepBtn {
			position: absolute;
			bottom: 30rpx;
			left: 50%;
			transform: translateX(-50%);
			width: 664rpx;
			height: 90rpx;
			border-radius: 45rpx;
			line-height: 90rpx;
			text-align: center;
			font-size: 30rpx;
			color: #fff;
			background: linear-gradient(to right,#fc4250, #fe744b);
		}
	}
</style>
